#include "time_mt.h"

#include <btime.h>

#include <QtTest/QTest>

using namespace core;
using namespace moduletest;

void Time_mt::getTime()
{
    QFETCH(uint, value);
    QFETCH(uint, result);

    QCOMPARE(value, result);
}

void Time_mt::getTime_data()
{
    const uint cons_res = 5;
    const uint sett_res = 10;

    BasicTime t(cons_res);

    QTest::addColumn<uint>("value");
    QTest::addColumn<uint>("result");

    QTest::newRow("Via constructor") << t.getTime() << cons_res;
    t.setTime(sett_res);
    QTest::newRow("Via setter") << t.getTime() << sett_res;
}

void Time_mt::getTimeUnit()
{
    QFETCH(uint, value);
    QFETCH(uint, result);

    QCOMPARE(value, result);
}

void Time_mt::getTimeUnit_data()
{
    const uint cons_res = 5;
    const uint sett_res = 10;

    BasicTime t(0, cons_res);

    QTest::addColumn<uint>("value");
    QTest::addColumn<uint>("result");

    QTest::newRow("Via constructor") << t.getTimeUnit() << cons_res;
    t.setTimeUnit(sett_res);
    QTest::newRow("Via setter") << t.getTimeUnit() << sett_res;
}

void Time_mt::setTime()
{
    const uint result = 5;

    BasicTime t(0);
    t.setTime(result);

    QCOMPARE(t.getTime(), result);
}

void Time_mt::setTimeUnit()
{
    const uint result = 5;

    BasicTime t(0, 0);
    t.setTimeUnit(result);

    QCOMPARE(t.getTimeUnit(), result);
}

void Time_mt::add()
{
    QFETCH(bool, value);
    QFETCH(bool, result);

    QCOMPARE(value, result);
}

void Time_mt::add_data()
{
    const bool no_overflow_res = false;
    const bool overflow_res = true;

    const uint addend = 5;

    BasicTime t(0, 0);

    QTest::addColumn<bool>("value");
    QTest::addColumn<bool>("result");

    QTest::newRow("Valid") << t.add(addend) << no_overflow_res;
    t.setTime(UINT_MAX);
    QTest::newRow("Overflow") << t.add(addend) << overflow_res;
}

void Time_mt::sub()
{
    QFETCH(bool, value);
    QFETCH(bool, result);

    QCOMPARE(value, result);
}

void Time_mt::sub_data()
{
    const bool no_overflow_res = false;
    const bool overflow_res = true;

    const uint subtrahend = 5;

    BasicTime t(5, 0);

    QTest::addColumn<bool>("value");
    QTest::addColumn<bool>("result");

    QTest::newRow("Valid") << t.sub(subtrahend) << no_overflow_res;
    t.setTime(0);
    QTest::newRow("Overflow") << t.sub(subtrahend) << overflow_res;
}

void Time_mt::operatorIncrement()
{
    QFETCH(uint, value);
    QFETCH(uint, result);

    QCOMPARE(value, result);
}

void Time_mt::operatorIncrement_data()
{
    const uint no_overflow_res = 5;
    const uint overflow_res = UINT_MAX;

    const uint increment = 5;

    BasicTime t(0, increment);

    QTest::addColumn<uint>("value");
    QTest::addColumn<uint>("result");

    ++t;
    QTest::newRow("Valid") << t.getTime() << no_overflow_res;
    t.setTime(UINT_MAX);
    ++t;
    QTest::newRow("Overflow") << t.getTime() << overflow_res;
}

void Time_mt::operatorDecrement()
{
    QFETCH(uint, value);
    QFETCH(uint, result);

    QCOMPARE(value, result);
}

void Time_mt::operatorDecrement_data()
{
    const uint no_overflow_res = 0;
    const uint overflow_res = 0;

    const uint decrement = 5;

    BasicTime t(5, decrement);

    QTest::addColumn<uint>("value");
    QTest::addColumn<uint>("result");

    --t;
    QTest::newRow("Valid") << t.getTime() << no_overflow_res;
    t.setTime(0);
    --t;
    QTest::newRow("Overflow") << t.getTime() << overflow_res;
}
